var t = require("../../../@babel/runtime/helpers/defineProperty"),
  e = u(require("../../../@babel/runtime/regenerator")),
  a = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  n = u(require("../../../config/page")),
  r = require("@/services/base/api"),
  i = u(require("../../../config/index")),
  o = require("@/utils/jump"),
  s = require("@/utils/report");
function u(t) {
  return t && t.__esModule ? t : { default: t };
}
Page({
  data: {
    position: !1,
    background: "#FAF3E8",
    titleColor: "#000",
    collections: [],
    defaultImg: i.default.defaultImg,
    rn: 10,
    pn: 1,
    load: !1,
    navBarHeight: 0,
    swiperTop: 0,
    CDN: i.default.CDN,
    times: 0,
    isOver: !1,
    isLoadMore: !0,
    total: 0,
  },
  toDetail: function (t) {
    (0, s.report)("fpage_treasure_click", {});
    var e = t.currentTarget.dataset.item.mainstay_id;
    (0, o.navigateTo)(n.default.PAGE_APPRECIATION_COLLECTION_CARD_INDEX, {
      id: e,
    });
  },
  onShow: function () {
    var t = this;
    return a(
      e.default.mark(function a() {
        var n, i, o, s, u, l, c;
        return e.default.wrap(function (e) {
          for (;;)
            switch ((e.prev = e.next)) {
              case 0:
                return (
                  t.setData({
                    pn: 1,
                    total: 0,
                    isOver: !1,
                    load: !0,
                    collections: [],
                  }),
                  (o = t.data),
                  (s = o.pn),
                  (u = o.rn),
                  (e.next = 4),
                  (0, r.getMainstayList)({ pn: s, rn: u, must_see: 1 })
                );
              case 4:
                (l = e.sent),
                  (c =
                    null != l &&
                    null !== (n = l.data) &&
                    void 0 !== n &&
                    n.total
                      ? l.data.total
                      : 0),
                  t.setData({
                    collections:
                      null != l &&
                      null !== (i = l.data) &&
                      void 0 !== i &&
                      i.list
                        ? l.data.list
                        : [],
                    isOver: t.data.collections.length >= c,
                    total: c,
                    isLoadMore: !1,
                  }),
                  t.data.collections.length && t.getInfo();
              case 8:
              case "end":
                return e.stop();
            }
        }, a);
      }),
    )();
  },
  onLoad: function () {
    var t = this;
    return a(
      e.default.mark(function a() {
        var n;
        return e.default.wrap(function (e) {
          for (;;)
            switch ((e.prev = e.next)) {
              case 0:
                (n = new Date().getTime()), t.setData({ times: n });
              case 2:
              case "end":
                return e.stop();
            }
        }, a);
      }),
    )();
  },
  getInfo: function () {
    var n = this;
    return a(
      e.default.mark(function a() {
        var i, o, s, u, l, c;
        return e.default.wrap(function (e) {
          for (;;)
            switch ((e.prev = e.next)) {
              case 0:
                return (
                  (e.next = 2),
                  (0, r.postExhibitInfo)({
                    exhibit_id: n.data.collections.map(function (t) {
                      if ("" !== t.exhibit_id) return t.exhibit_id;
                    }),
                  })
                );
              case 2:
                if (
                  ((o = e.sent),
                  (s = n.data.collections),
                  null == o ||
                    null === (i = o.data) ||
                    void 0 === i ||
                    !i.length)
                ) {
                  e.next = 12;
                  break;
                }
                if (
                  (o.data.forEach(function (e) {
                    var a = s.findIndex(function (t) {
                      return t.exhibit_id === e.exhibit_id;
                    });
                    if (-1 !== a) {
                      e.pic = e.album;
                      var r = "collections[".concat(a, "]");
                      n.setData(t({}, r, Object.assign(e, s[a])));
                    }
                  }),
                  null !==
                    (u = s.filter(function (t) {
                      return t.poi_id;
                    })) &&
                    void 0 !== u &&
                    u.length)
                ) {
                  e.next = 8;
                  break;
                }
                return e.abrupt("return");
              case 8:
                return (
                  (e.next = 10),
                  (0, r.getPositionInfo)({
                    poi_id: s
                      .filter(function (t) {
                        return t.poi_id;
                      })
                      .map(function (t) {
                        return t.poi_id;
                      }),
                  })
                );
              case 10:
                null != (c = e.sent) &&
                  null !== (l = c.data) &&
                  void 0 !== l &&
                  l.length &&
                  c.data.map(function (e) {
                    var a = s.findIndex(function (t) {
                      return t.poi_id === e.poi_id;
                    });
                    if (-1 !== a) {
                      e.poi_name = e.name;
                      var r = "collections[".concat(a, "]");
                      n.setData(t({}, r, Object.assign(e, s[a])));
                    }
                  });
              case 12:
                n.setData({ load: !1 });
              case 13:
              case "end":
                return e.stop();
            }
        }, a);
      }),
    )();
  },
  onShareAppMessage: function () {
    return {
      title: i.default.share.title,
      imageUrl: i.default.share.pic,
      path: n.default.PAGE_RECOMMEND_COLLECTION,
    };
  },
  onReachBottom: function () {
    var t = this;
    return a(
      e.default.mark(function a() {
        var n, i, o, s, u, l, c;
        return e.default.wrap(function (e) {
          for (;;)
            switch ((e.prev = e.next)) {
              case 0:
                if (
                  ((i = t.data.collections),
                  (o = t.data),
                  (s = o.pn),
                  (u = o.rn),
                  (l = o.total),
                  !t.data.isOver)
                ) {
                  e.next = 4;
                  break;
                }
                return e.abrupt("return");
              case 4:
                return (
                  t.setData({ isLoadMore: !0 }),
                  (e.next = 7),
                  (0, r.getMainstayList)({ pn: s + 1, rn: u, must_see: 1 })
                );
              case 7:
                null != (c = e.sent) &&
                  null !== (n = c.data) &&
                  void 0 !== n &&
                  n.list &&
                  (i = i.concat(c.data.list)),
                  t.setData({ collections: i, pn: s + 1, isLoadMore: !1 }),
                  t.getInfo(),
                  i.length >= l && t.setData({ isOver: !0 });
              case 12:
              case "end":
                return e.stop();
            }
        }, a);
      }),
    )();
  },
});
